package com.cn.kabalifeuser.base;

import android.os.Bundle;

import androidx.annotation.Nullable;


/**
 * Created by xiaolin on 2018/9/19.
 * function
 */

public abstract class IBaseLazyFragment<V, T extends BasePresenter<V>> extends BaseFragment {
    public int pagehttp = 1;
    public int pageNum = 10;
    protected T mPresenter;

    private boolean visibleToUser;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //判断是否使用MVP模式
        mPresenter = createPresenter();
        if (mPresenter != null) {
            mPresenter.attachView((V) this);//因为之后所有的子类都要实现对应的View接口
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        if (!visibleToUser) {
            visibleToUser = true;
            lazyLoad();
        }
    }

    /**
     * 懒加载，只有在Fragment第一次创建且第一次对用户可见
     */
    protected abstract void lazyLoad();


    //用于创建Presenter和判断是否使用MVP模式(由子类实现)
    protected abstract T createPresenter();


}
